<!DOCTYPE html>
<html class="index_body">
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=10">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Cache" content="no-cache">
    <title></title>
    <link rel="stylesheet" href="/Public/mui/computer/css/bootstrap.css"/>
    <link rel="stylesheet" href="/Public/mui/computer/css/index.css?v=2"/>
    <link rel="stylesheet"  href="/Public/mui/static/bower_components/sweetalert/dist/sweetalert.css">
</head>
<body class="index_body">
<include file="Lay:heder" />
<form action="/admin/Stock/addCarPrice" id="channel_form" method="post" enctype="multipart/form-data">
<div id="section" style="padding-top: 20px;padding-bottom: 20px">
    <table class="table table-striped table-hover car_price_table all_table">
        <thead class="all_thead">
            <tr>
                <th>指导价</th>
                <th>优优价</th>
                <th>VS指导价</th>
                <th>服务费</th>
                <th>月供(首年)</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td class="td_input">
                    <input type="number" name="guide_price" value=""/>元
                </td>
                <td class="td_input">
                    <input type="number" name="jdc_price"  value=""/>元
                </td>
                <td class="td_input">
                    <input type="number" name="preferential_ratio" value=""/>%
                </td>
                <td class="td_input">
                    <input type="number" name="first_pay" value=""/>元
                </td>
                <td class="td_input">
                    <input type="number" name="month_pay"  value=""/>元
                </td>
            </tr>
        </tbody>
    </table>

    <table class="table table-striped table-hover car_price_table all_table">
        <thead class="all_thead">
        <tr>
            <th>期数</th>
            <th>尾款</th>
            <th>尾款月供</th>
            <th>尾款期数</th>
            <!-- <th>指导价</th>
            <th>优优价</th>
            <th>VS指导价</th>
            <th>服务费</th>
            <th>月供(首年)</th> -->
        </tr>
        </thead>
        <tbody id="price">
            <foreach name="pricelist" item="v" key="k">
                 <tr>
                     <td class="td_input"><input type="number" name="pay_month{{$k}}" class="pay_month" value="{{$v.pay_month}}" readonly='readonly' style="width: 20%;" />期</td>
                     <!-- <td class="td_input"><input type="number" name="surplus_money{{$k}}"     value="{{$v.surplus_money}}" class="surplus_money" />元</td>
                     <td class="td_input"><input type="number" name="surplus_month_pay{{$k}}" value="{{$v.surplus_month_pay}}" class="surplus_month_pay" />元</td> -->
                     <td class="td_input"><input type="number" name="surplus_money{{$k}}"     value="" class="surplus_money" />元</td>
                     <td class="td_input"><input type="number" name="surplus_month_pay{{$k}}" value="" class="surplus_month_pay" />元</td>
                     <td class="td_input"><input type="number" name="surplus_pay_month{{$k}}" value="{{$v.surplus_pay_month}}" class="surplus_pay_month" />期</td>
                 </tr>
             </foreach>
        </tbody>
    </table>
    <include file="News:news" />
    <input type="hidden" name="carnum" id="gpsaddress" value=""><!--获取维度-->
    <div class="button_div">
        <button type="submit" class="btn btn-primary">保存</button>
    </div>
</div>
</form>
<script src="/Public/mui/computer/js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="/Public/mui/static/bower_components/sweetalert/dist/sweetalert.min.js"></script>
<script type="text/javascript" src="/Public/mui/computer/js/functions.js?v=asdf2"></script>
<script type="text/javascript" src="/Public/mui/computer/js/sotck.js?v=asdf2"></script>
<script type="text/javascript" src="/Public/mui/computer/js/jquery.form.js?v=asdf2"></script>
<script src="/Public/mui/computer/js/back.js"></script>
<script>
$("#logo_type").attr("src","/Public/mui/computer/img/kucun.png");
eval('var paddstock = (<?php echo json_encode($pricelist)?>)');
// for (i in paddstock) {
//     $('.surplus_money').val(paddstock[i]['surplus_money']);
//     $('.surplus_month_pay').val(paddstock[i]['surplus_month_pay']);
//     $('.pay_month_name').val(paddstock[i]['pay_month_name']);
//     console.log(paddstock[i]['pay_month'])
//     $('.pay_month').val(paddstock[i]['pay_month']);
// }
console.log(paddstock);
$("input[name='guide_price']").val("{{$pricelist[0]['guide_price']}}");
$("input[name='jdc_price']").val("{{$pricelist[0]['jdc_price']}}");
$("input[name='preferential_ratio']").val("{{$pricelist[0]['preferential_ratio']}}");
$("input[name='first_pay']").val("{{$pricelist[0]['first_pay']}}");
$("input[name='month_pay']").val("{{$pricelist[0]['month_pay']}}");
$("#gpsaddress").val("{{$pricelist[0]['carnum']}}");
function  reginput(){
    var price = $("input[name='guide_price']").val();
    if(price == ""){
        sweetAlert('',"指导价未填写",'error');
        return false;
    }
    var jdcprice = $("input[name='jdc_price']").val();
    if(jdcprice == ""){
        sweetAlert('',"优优价未填写",'error');
        return false;
    }
    var preferratio = $("input[name='preferential_ratio']").val();
    if(preferratio == ""){
        sweetAlert('',"VS指导价未填写",'error');
        return false;
    }
    var firstpay = $("input[name='first_pay']").val();
    if(firstpay == ""){
        sweetAlert('',"服务费未填写",'error');
        return false;
    }
    var monthpay = $("input[name='month_pay']").val();
    if(monthpay == ""){
        sweetAlert('',"月供(首年)未填写",'error');
        return false;
    }
    var gpsadmun = $("#gpsaddress").val();
    if(gpsadmun == ""){
        sweetAlert('',"信息获取失败,",'error');
        return false;
    }
    return true;
}
$('#channel_form').ajaxForm({
    beforeSubmit: function () {
        if(!reginput()){
            return false;
        }
    },  //提交前的回调函数
  success: function (response) {
    if(response.ret == "OK"){
            sweetAlert('',"添加成功",'success');
            setTimeout(function () {
                      location.href = '/admin/Stock/car_guanli';
                    },2000);
        }else if(response.ret == "ERROR"){
            sweetAlert('',response.msg,'error');
            return false;
        }else{
             sweetAlert('',"添加失败",'error');
             return false;
        }
    },
    dataType: 'json',
    xhrFields: {
       withCredentials: true
    }
});
</script>
</body>
</html>